<template>
  <van-nav-bar :title="title" border z-index="101" fixed>
    <template #left>
      <slot name="left">
        <div class="back" v-if="back" @click="gotoback">
          <van-icon name="arrow-left" size="18" color="#ff5f16" />
          <span>返回</span>
        </div>
      </slot>
    </template>
    <template #right>
      <van-popover
        v-model="showPopover"
        @select="toggleclick"
        theme="dark"
        placement="bottom-end"
        trigger="click"
        :actions="actions"
      >
        <template #reference>
          <van-icon name="ellipsis" size="22" />
        </template>
      </van-popover>
    </template>
  </van-nav-bar>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: "",
    },
    back: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      showPopover: false,
      actions: [
        {
          text: "搜索",
          icon: "search",
          name: "search",
          disabled: this.$route.name == "search",
        },
        {
          text: "首页",
          icon: "wap-home-o",
          name: "movie",
          disabled: this.$route.name == "movie",
        },
        {
          text: "我的信息",
          icon: "more-o",
          name: "mine",
          disabled: this.$route.name == "mine",
        },
        {
          text: "登录",
          icon: "user-o",
          name: "login",
          disabled: this.$route.name == "login",
        },
        {
          text: "定位",
          icon: "location-o",
          name: "city",
          disabled: this.$route.name == "city",
        },
      ],
    };
  },
  methods: {
    toggleclick(v) {
      console.log(v);
      this.$router.push({ name: v.name });
    },
    gotoback() {
      this.$router.back();
    },
  },
};
</script>

<style lang="scss" scoped>
.back {
  display: flex;
  align-items: center;
  height: 100%;
  span {
    color: #ff5f16;
    line-height: 1;
    margin-top: 1px;
  }
}
</style>